package com.situ.system.util;

import java.io.Writer;
import java.util.Collection;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;


public class FmtRequest {
	public static void write(Writer wr, String val) {
		try {
			wr.write(val);
			wr.flush();
			wr.close();
			wr = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void write(Writer wr, Object val) {
		if (val instanceof Collection<?>)
			write(wr, new JSONArray((Collection<?>) val).toString());
		else if (val instanceof Map<?, ?>)
			write(wr, new JSONObject((Map<?, ?>) val).toString());
		else if (val instanceof String)
			write(wr, val.toString());
		else
			write(wr, new JSONObject(val).toString());
	}
}
